﻿package mortal.game.view.common.guide
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.daily.*;
    import mortal.game.view.mainUI.Navbar.*;
    import mortal.mvc.core.*;

    public class AutoGuideRedPoint extends Object
    {
        private var _map:Dictionary;
        public static const DailyVitalityAdd:String = "DailyVitalityAdd";
        public static const GuildGodTree:String = "GuildGodTree";
        private static var _instance:AutoGuideRedPoint;

        public function AutoGuideRedPoint()
        {
            this.initMap();
            this.addEvents();
            return;
        }// end function

        public function onDailyVitalityAdd(param1:Object = null) : void
        {
            if (Cache.instance.daily.data == null)
            {
                return;
            }
            var _loc_2:* = Cache.instance.daily;
            var _loc_3:* = DailyConfig.instance.getActivityItem((_loc_2.data.level + 1));
            var _loc_4:* = DailyUtil.maxActivity;
            if (_loc_3 && _loc_2.data.activity >= _loc_3.activity && _loc_3.activity <= _loc_4)
            {
                this.setValueByName(DailyVitalityAdd, true);
            }
            else
            {
                this.setValueByName(DailyVitalityAdd, false);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideRedPointRefresh));
            return;
        }// end function

        private function onCopyEnter(param1:Object) : void
        {
            var _loc_3:Boolean = false;
            var _loc_4:Array = null;
            var _loc_5:TreeBuff = null;
            var _loc_6:Array = null;
            var _loc_7:int = 0;
            var _loc_2:* = Cache.instance.guild.CurrentTreeBuff;
            if (_loc_2)
            {
                _loc_4 = GuildUtil.roleBuff;
                for each (_loc_5 in _loc_2)
                {
                    
                    _loc_6 = _loc_5.copyCode.split("#");
                    _loc_7 = Cache.instance.copy.copyInfo.code;
                    if (_loc_6 && _loc_6.indexOf(_loc_7.toString()) != -1 && _loc_4.indexOf(_loc_5.buffId) == -1)
                    {
                        _loc_3 = true;
                        break;
                    }
                }
                if (_loc_3)
                {
                    this.setValueByName(GuildGodTree, true);
                }
                else
                {
                    this.setValueByName(GuildGodTree, false);
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideRedPointRefresh));
            }
            return;
        }// end function

        private function onCopyLeave(param1:Object) : void
        {
            this.setValueByName(GuildGodTree, false);
            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideRedPointRefresh));
            return;
        }// end function

        private function onNavBarRedPointShowOrHide(event:DataEvent) : void
        {
            var _loc_5:GBitmap = null;
            var _loc_2:* = event.data.mType;
            var _loc_3:* = event.data.pType;
            var _loc_4:* = GameController.navbar.view as NavbarModule;
            var _loc_6:* = _loc_4.btnBottomContainer.getChildByName(_loc_2) as GLoadedButton;
            if (this.getValueByName(_loc_3))
            {
                EffectManager.glowFilterReg(_loc_6);
            }
            else
            {
                EffectManager.glowFilterUnReg(_loc_6);
            }
            return;
        }// end function

        private function onNavBarButtonPosUpdate(event:DataEvent) : void
        {
            var _loc_2:Object = null;
            var _loc_3:String = null;
            for (_loc_3 in this._map)
            {
                
                _loc_2 = this._map[_loc_3];
                if (_loc_2.show)
                {
                    this.onNavBarRedPointShowOrHide(new DataEvent(EventName.NavBarRedPointShowOrHide, {mType:_loc_2.mType, pType:_loc_3}));
                }
            }
            return;
        }// end function

        private function addEvents() : void
        {
            EventUtil.addSelfEvent(EventName.NavbarButtonUIRowInited, this.initHd, true);
            Dispatcher.addEventListener(EventName.NavBarButtonPosUpdate, this.onNavBarButtonPosUpdate);
            NetDispatcher.addCmdListener(ServerCommand.DailyVitalityAdd, this.onDailyVitalityAdd);
            NetDispatcher.addCmdListener(ServerCommand.Copy_EnterCopy, this.onCopyEnter);
            NetDispatcher.addCmdListener(ServerCommand.Copy_LeaveCopy, this.onCopyLeave);
            return;
        }// end function

        private function initMap() : void
        {
            this._map = new Dictionary();
            this._map[DailyVitalityAdd] = {show:false, mType:ModuleType.Daily};
            this._map[GuildGodTree] = {show:false, mType:ModuleType.Guild};
            return;
        }// end function

        private function initHd(param1:Object) : void
        {
            this.onDailyVitalityAdd();
            this.onNavBarButtonPosUpdate(null);
            return;
        }// end function

        public function setValueByName(param1:String, param2:Boolean, param3:Boolean = true) : void
        {
            this._map[param1].show = param2;
            this.onNavBarRedPointShowOrHide(new DataEvent(EventName.NavBarRedPointShowOrHide, {mType:this._map[param1].mType, pType:param1}));
            return;
        }// end function

        public function getValueByName(param1:String) : Boolean
        {
            return this._map[param1].show as Boolean;
        }// end function

        private function onTimeOut() : void
        {
            this.onDailyVitalityAdd();
            this.register();
            return;
        }// end function

        public function register() : void
        {
            var _loc_1:* = ClockManager.instance.nowDate.time + 2 * 12 * 5 * 60 * 1000;
            ClockManager.instance.addDateCall(new Date(_loc_1), this.onTimeOut);
            return;
        }// end function

        public static function get instance() : AutoGuideRedPoint
        {
            if (_instance == null)
            {
                _instance = new AutoGuideRedPoint;
            }
            return _instance;
        }// end function

    }
}
